define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'evaluation/order/index' + location.search,
                    add_url: 'evaluation/order/add',
                    edit_url: 'evaluation/order/edit',
                    del_url: 'evaluation/order/del',
                    multi_url: 'evaluation/order/multi',
                    table: 'evaluation_order',
                }
            });

            var table = $("#table");
            var  stvisible = '=';
            var  stvisible2 = true;
            if(Config.org_cate_id > 0){
                stvisible = false;
                stvisible2 = false;
            }
            table.on('post-common-search.bs.table', function (event, table) {
                $(".commonsearch-table").find('.btn-success').html('搜索');
                $(".commonsearch-table").find('.btn-default').html('刷新');
                $(".columns-right").hide();
                $('.form-commonsearch').attr('autocomplete', 'off');
            });
            table.on('load-success.bs.table', function (e, data) {
                //这里可以获取从服务端获取的JSON数据
                //这里我们手动设置底部的值
                $("#total_num").text(data.extend.total_num);
                $("#total_peo").text(data.extend.total_peo);
                $("#total_money").text(data.extend.total_money);
            });
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        //{checkbox: true},
                        {field: 'sort', title: __('序号'),operate:false},
                        {field: 'o.id', title: __('单位名称'),visible: stvisible2, operate:stvisible, searchList: $.getJSON('usechart/searchlist'), formatter: Controller.api.formatter.custom},
                        {field: 'order_sn', title: __('Order_sn'), operate:'LIKE'},
                        {field: 'user_id', title: __('用户ID'), operate:false},
                        {field: 'name', title: __('Name'), operate:false},
                        // {field: 'user.user_type', title: '用户类型', searchList: {"0":'学生',"1":'家长',"2":'访客',"3":'教师'}, formatter: Table.api.formatter.normal},
                        {field: 'usertype', title: __('用户类型'), formatter: Table.api.formatter.normal,searchList: {"1":__('单位用户'),"2":__('访客')}},
                        {field: 'mobile', title: __('Mobile'), operate:false},
                        {field: 'evaluation.name', title: __('Evaluation.name'), operate:false},
                        {field: 'type', title: __('Type'), operate:false, searchList: {"0":__('Type 0'),"1":__('Type 1'),"2":__('Type 2')}, formatter: Table.api.formatter.normal},
                        {field: 'price', title: __('Price'), operate:false},
                        {field: 'process_type', title: '测评完成状态', operate:false, searchList: {"0":'未答题',"2":'正在答题',"4":'待生成报告',"5":'已生成报告'}, formatter: Table.api.formatter.normal},

                        {field: 'createtime', title: __('订单时间'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},

                        // {field: 'sex', title: __('Sex'), searchList: {"1":__('Sex 1'),"2":__('Sex 2')}, formatter: Table.api.formatter.status},
                        // {field: 'height', title: __('Height'),operate:false},
                        // {field: 'weight', title: __('Weight'),operate:false},
                        // {field: 'birthday', title: __('Birthday'),operate:false},
                        // {field: 'age', title: __('Age'),operate:false},
                        // {field: 'user.nickname', title: __('User.nickname'), operate:'LIKE'},
                        // {field: 'openid', title: __('Openid'),operate:false},
                        // {field: 'scalar_id', title: __('Scalar_id'), searchList: {"7":__('Scalar_id 7'),"21":__('Scalar_id 21'),"28":__('Scalar_id 28'),"50":__('Scalar_id 50'),"52":__('Scalar_id 52'),"54":__('Scalar_id 54'),"73":__('Scalar_id 73'),"83":__('Scalar_id 83'),"84":__('Scalar_id 84'),"85":__('Scalar_id 85')}, formatter: Table.api.formatter.status},
                        // {field: 'line_number', title: __('Line_number'), operate:'LIKE'},
                        // {field: 'evaluation.name', title: __('Evaluation.name'), operate:'LIKE'},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ],
                showToggle: false,
                showColumns: false,
                showExport: false,
                searchFormVisible: true,
                search:false,
                onLoadSuccess:function(){
                    // 这里就是数据渲染结束后的回调函数
                    $(".btn-editone").data("area", ["100%","100%"]);
                    $(".columns-right").hide();
                }
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter: {//渲染的方法
                custom: function (value, row, index) {
                    //添加上btn-change可以自定义请求的URL进行数据处理
                    return row.oname;
                }
            }
        }
    };
    return Controller;
});